home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / desaware / spyworks / coop1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-24  |  7.5 KB  |  238 lines

  1. VERSION 4.00
  2. Begin VB.Form Coop1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Coop1"
  5.    ClientHeight    =   2115
  6.    ClientLeft      =   1095
  7.    ClientTop       =   1485
  8.    ClientWidth     =   5010
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   0
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    ForeColor       =   &H80000008&
  19.    Height          =   2520
  20.    Left            =   1035
  21.    LinkTopic       =   "Form1"
  22.    ScaleHeight     =   2115
  23.    ScaleWidth      =   5010
  24.    Top             =   1140
  25.    Width           =   5130
  26.    Begin VB.CommandButton ExitBut 
  27.       Appearance      =   0  'Flat
  28.       BackColor       =   &H80000005&
  29.       Caption         =   "Exit"
  30.       Height          =   465
  31.       Left            =   3240
  32.       TabIndex        =   6
  33.       Top             =   1200
  34.       Width           =   1665
  35.    End
  36.    Begin VB.TextBox TotalText 
  37.       Height          =   315
  38.       Left            =   870
  39.       MaxLength       =   12
  40.       TabIndex        =   5
  41.       Text            =   "123456"
  42.       Top             =   1290
  43.       Width           =   1245
  44.    End
  45.    Begin VB.TextBox AmountText 
  46.       Height          =   315
  47.       Left            =   870
  48.       MaxLength       =   12
  49.       TabIndex        =   4
  50.       Text            =   "7.75"
  51.       Top             =   900
  52.       Width           =   1245
  53.    End
  54.    Begin VB.TextBox CountText 
  55.       Height          =   315
  56.       Left            =   870
  57.       MaxLength       =   4
  58.       TabIndex        =   3
  59.       Text            =   "249"
  60.       Top             =   510
  61.       Width           =   1245
  62.    End
  63.    Begin VB.TextBox CompanyText 
  64.       Height          =   315
  65.       Left            =   870
  66.       MaxLength       =   24
  67.       TabIndex        =   2
  68.       Text            =   "Desaware SpyWorks Pro"
  69.       Top             =   120
  70.       Width           =   2265
  71.    End
  72.    Begin VB.CommandButton SendMessBut 
  73.       Appearance      =   0  'Flat
  74.       BackColor       =   &H80000005&
  75.       Caption         =   "Send Message"
  76.       Height          =   465
  77.       Left            =   3240
  78.       TabIndex        =   1
  79.       Top             =   660
  80.       Width           =   1665
  81.    End
  82.    Begin VB.CommandButton LaunchBut 
  83.       Appearance      =   0  'Flat
  84.       BackColor       =   &H80000005&
  85.       Caption         =   "Launch New App"
  86.       Height          =   465
  87.       Left            =   3240
  88.       TabIndex        =   0
  89.       Top             =   120
  90.       Width           =   1665
  91.    End
  92.    Begin Cbkd.Callback Callback1 
  93.       Left            =   2550
  94.       Top             =   1140
  95.       _Version        =   262144
  96.       _ExtentX        =   847
  97.       _ExtentY        =   847
  98.       _StockProps     =   0
  99.       Type            =   6
  100.       IntVersion      =   5
  101.    End
  102.    Begin VB.Label Label2 
  103.       Height          =   285
  104.       Left            =   120
  105.       TabIndex        =   11
  106.       Top             =   1740
  107.       Width           =   4785
  108.    End
  109.    Begin VB.Label Label1 
  110.       Alignment       =   1  'Right Justify
  111.       Appearance      =   0  'Flat
  112.       BackColor       =   &H00C0C0C0&
  113.       Caption         =   "Long"
  114.       ForeColor       =   &H80000008&
  115.       Height          =   255
  116.       Index           =   3
  117.       Left            =   120
  118.       TabIndex        =   10
  119.       Top             =   1320
  120.       Width           =   705
  121.    End
  122.    Begin VB.Label Label1 
  123.       Alignment       =   1  'Right Justify
  124.       Appearance      =   0  'Flat
  125.       BackColor       =   &H00C0C0C0&
  126.       Caption         =   "Single"
  127.       ForeColor       =   &H80000008&
  128.       Height          =   255
  129.       Index           =   2
  130.       Left            =   60
  131.       TabIndex        =   9
  132.       Top             =   930
  133.       Width           =   765
  134.    End
  135.    Begin VB.Label Label1 
  136.       Alignment       =   1  'Right Justify
  137.       Appearance      =   0  'Flat
  138.       BackColor       =   &H00C0C0C0&
  139.       Caption         =   "Integer"
  140.       ForeColor       =   &H80000008&
  141.       Height          =   255
  142.       Index           =   1
  143.       Left            =   120
  144.       TabIndex        =   8
  145.       Top             =   540
  146.       Width           =   705
  147.    End
  148.    Begin VB.Label Label1 
  149.       Alignment       =   1  'Right Justify
  150.       Appearance      =   0  'Flat
  151.       BackColor       =   &H00C0C0C0&
  152.       Caption         =   "String"
  153.       ForeColor       =   &H80000008&
  154.       Height          =   255
  155.       Index           =   0
  156.       Left            =   150
  157.       TabIndex        =   7
  158.       Top             =   150
  159.       Width           =   675
  160.    End
  161. Attribute VB_Name = "Coop1"
  162. Attribute VB_Creatable = False
  163. Attribute VB_Exposed = False
  164. Option Explicit
  165. Dim NewShellApp As Long
  166. Dim OtherAppMainWindowHwnd As Long
  167. Dim PrivateCoopMessage As Long
  168. Private Sub Callback1_EnumWindows(hwnd As Long, lpData As Long, retval As Long)
  169. Dim threadid As Long, processid As Long, res As Long
  170. Dim ClassName As String
  171.     ' Check if this window is part of the process we launched
  172.     threadid = GetWindowThreadProcessId(hwnd, processid)
  173.     ' The default return value is already TRUE to continue enumeration
  174.     If processid <> NewShellApp Then Exit Sub
  175.     ClassName = String$(32, 0)
  176.     res = GetClassName(hwnd, ClassName, Len(ClassName) - 1)
  177.     ClassName = Left$(ClassName, InStr(1, ClassName, Chr$(0)) - 1)
  178.     If ClassName = THUNDERRTMAIN Then Exit Sub
  179.     ' Stop the enumeration once we find the window
  180.     retval = 0
  181.     OtherAppMainWindowHwnd = hwnd
  182.     label2.Caption = Hex$(hwnd)
  183. End Sub
  184. Private Sub ExitBut_Click()
  185.     Unload Me
  186. End Sub
  187. Private Sub Form_Load()
  188.     PrivateCoopMessage = RegisterWindowMessage(COOP_MESSAGE)
  189. End Sub
  190. Private Sub LaunchBut_Click()
  191. Dim res As Integer
  192.     NewShellApp = Shell(App.Path & "\COOP2.EXE", 1)
  193.     ' If Shell was successful then
  194.     If NewShellApp Then
  195.         ' Get the top level window handle of the newly launched application
  196.         res = EnumWindows(Callback1.ProcAddress, 0)
  197.     End If
  198. End Sub
  199. Private Sub SendMessBut_Click()
  200. Dim cs As CoopStructure
  201. Dim wp As Long, lp As Long, lres As Double, threadid As Long
  202.     If PrivateCoopMessage Then
  203.         ' Note that the Max length of CompanyText is
  204.         ' set to the size of the CompanyName element.
  205.         ' The other Text controls also have limited Max
  206.         ' length to prevent overflow.
  207.         lp = dwGetAddressForObject(cs.CompanyName(1))
  208.         dwCopyDataByString CompanyText.Text, lp, 24
  209.         
  210.         ' Prevent invalid data type
  211.         On Error GoTo InvalidCount
  212.         cs.count = CInt(CountText.Text)
  213.         On Error GoTo InvalidAmount
  214.         cs.Amount = CSng(AmountText.Text)
  215.         On Error GoTo InvalidTotal
  216.         cs.Total = CLng(TotalText.Text)
  217.         ' Turn off error checking
  218.         On Error GoTo 0
  219.         
  220.         ' Get address of the structure and send it to the other application.
  221.         lp = dwGetAddressForObject(cs)
  222.         ' get process id to send
  223.         threadid = GetWindowThreadProcessId(hwnd, wp)
  224.         lres = SendMessageBynum(OtherAppMainWindowHwnd, PrivateCoopMessage, wp, lp)
  225.         label2.Caption = Hex$(lres)
  226.     End If
  227.     Exit Sub
  228. InvalidCount:
  229.     cs.count = 0
  230.     Resume Next
  231. InvalidAmount:
  232.     cs.Amount = 0
  233.     Resume Next
  234. InvalidTotal:
  235.     cs.Total = 0
  236.     Resume Next
  237. End Sub
  238.